package thread1;

public class NotifyExample {

    private static final Object lock = new Object();
    private static boolean isReady = false;

    public static void main(String[] args) throws InterruptedException {
        Thread waitThread = new Thread(new Runnable() {

            @Override
            public void run() {
                synchronized (lock) {
                    while (!isReady) {

                        System.out.println("wait start");
                        try {
                            lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                    System.out.println("wait end");
                }
            }
        });
        Thread notifyThread = new Thread(()->{
           synchronized (lock) {
               isReady = true;
               System.out.println("notify start");
               lock.notify();
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               System.out.println("notify end");
           }
        });
        waitThread.start();
        Thread.sleep(200);
        notifyThread.start();
    }

}
